<!DOCTYPE html>
<html class="x-admin-sm">

    <head>
        <meta charset="UTF-8">
        <title>目的地管理</title>
        <meta name="renderer" content="webkit">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
        <link rel="stylesheet" href="../../static/css/font.css">
        <link rel="stylesheet" href="../../static/css/xadmin.css">

        <script src="../../static/js/jquery.min.js"></script>

        <link rel="stylesheet" href="../../static/lib/layui/css/layui.css" media="all">
        <script type="text/javascript" src="../../static/lib/layui/layui.js" charset="utf-8"></script>
        <script type="text/javascript" src="../../static/js/xadmin.js"></script>
        <script src="../../static/lib/layui/transfer.js"></script>
        <!--       // <script src="static/lib/layui/lay/modules/transfer.js"></script>-->
        <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
            <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>

    </head>

    <body>
        <div class="layui-fluid">
            <div class="layui-row">
                <form class="layui-form" id="paiche">
                    <div class="layui-form-item">
                        <label for="" class="layui-form-label">
                    </div>
                    <div class="layui-form-item">
                        <label for="" class="layui-form-label">
                            <span class="x-red"></span>目的地</label>
                            <input type="text" id="destination" name="destination" class="layui-input" style="width: 300px" ng-model="entity.destination">
                    </div>
                    <div class="layui-form-item">
                        <label for="" class="layui-form-label"></label>
                        <button id="save" class="layui-btn">保存</button>
                    </div>
                </form>
        </div>
        </div>
        <script type="text/javascript">
            $(function () {
                $("#save").click(function () {
                    var destination = $("#destination").val();
                    console.log("destination==>",destination);
                    $.ajax({
                        url : "/destination/save",
                        type : 'post',
                        contentType:'application/json;charset=utf-8',
                        dataType : "JSON",
                        data : JSON.stringify({
                            'desName' : destination
                        }),
                        async : false,
                        success : function(data) {
                            alert("已成功添加目的地！")
                            var index = parent.layer
                                .getFrameIndex(window.name), p = parent;

                            //然后下面先关闭子窗口
                            parent.layer.close(index);
                            //再刷新
                            p.location.reload();
                        }
                    })
                });
            })

            layui.use(['layer','form'], function() {
                var form = layui.form;
                var layer = layui.layer;
                    form.on('select(myselect)', function(data){
                        console.log(data.value);
                        var driveName=data.value;
                        $.ajax({
                            type: 'POST',
                            url: '/paiche/mantodept/'+driveName,
                            dataType:  'json',
                            success: function(data){
                                var department=data.data[0].t_department;
                                console.log(department);
                                //检查项目添加到下拉框中
                                $.ajax({
                                    url: '/useMan/tdriverDepartment',
                                    dataType: 'json',
                                    type: 'get',
                                    success: function (data) {
                                        console.log(data);
                                        $.each(data.data, function (index, item) {
                                            //alert(item.carId)
                                            $('#department').append(new Option(item.departmentName, item.departmentNum));// 下拉菜单里添加元素
                                            $('#department').val(department);
                                        });

                                        //重新渲染 固定写法
                                        layui.form.render("select");
                                    }
                                })
                            }
                        });
                    });


                /* form.render(); */
                //检查项目添加到下拉框中
                $.ajax({
                    url: '/TCar/tcarNo',
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        console.log(data);

                        $.each(data.data, function (index, item) {
                            //alert(item.carId)
                            $('#carId').append(new Option(item.carNo, item.carId));// 下拉菜单里添加元素
                        });

                        //重新渲染 固定写法
                        layui.form.render("select");
                    }
                })

                // 用车人
                $.ajax({
                    url: '/useMan/tdriverName',
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        console.log(data.data);

                        $.each(data.data, function (index, item) {
                            //alert(item.carId)
                            $('#driverName').append(new Option(item.driverName, item.driverId));// 下拉菜单里添加元素
                        });

                        //重新渲染 固定写法
                        layui.form.render("select");
                    }
                })

                /* form.render(); */
                //检查项目添加到下拉框中
                $.ajax({
                    url: '/TDriver/tdriverName',
                    dataType: 'json',
                    type: 'get',
                    success: function (data) {
                        console.log(data);

                        $.each(data.data, function (index, item) {
                            //alert(item.driverId)
                            $('#driverId').append(new Option(item.driverName, item.driverId));// 下拉菜单里添加元素
                        });

                        //重新渲染 固定写法
                        layui.form.render("select");
                    }
                })

            });

            // 日期处理
            layui.use('laydate', function(){
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: '#driveTime' //指定元素
                    ,type: 'datetime'
                });

                laydate.render({
                    elem:'#returnTime'
                    ,type:'datetime'
                })
            });

            // 日期转换
            function Format(now,mask) {
                var d = new Date(now);
                var zeroize = function (value, length)
                {
                    if (!length) length = 2;
                    value = String(value);
                    for (var i = 0, zeros = ''; i < (length - value.length); i++)
                    {
                        zeros += '0';
                    }
                    return zeros + value;
                };

                return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|yy(?:yy)?|([hHMstT])\1?|[lLZ])\b/g, function ($0)
                {
                    switch ($0)
                    {
                        case 'd': return d.getDate();
                        case 'dd': return zeroize(d.getDate());
                        case 'ddd': return ['Sun', 'Mon', 'Tue', 'Wed', 'Thr', 'Fri', 'Sat'][d.getDay()];
                        case 'dddd': return ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][d.getDay()];
                        case 'M': return d.getMonth() + 1;
                        case 'MM': return zeroize(d.getMonth() + 1);
                        case 'MMM': return ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'][d.getMonth()];
                        case 'MMMM': return ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'][d.getMonth()];
                        case 'yy': return String(d.getFullYear()).substr(2);
                        case 'yyyy': return d.getFullYear();
                        case 'h': return d.getHours() % 12 || 12;
                        case 'hh': return zeroize(d.getHours() % 12 || 12);
                        case 'H': return d.getHours();
                        case 'HH': return zeroize(d.getHours());
                        case 'm': return d.getMinutes();
                        case 'mm': return zeroize(d.getMinutes());
                        case 's': return d.getSeconds();
                        case 'ss': return zeroize(d.getSeconds());
                        case 'l': return zeroize(d.getMilliseconds(), 3);
                        case 'L': var m = d.getMilliseconds();
                            if (m > 99) m = Math.round(m / 10);
                            return zeroize(m);
                        case 'tt': return d.getHours() < 12 ? 'am' : 'pm';
                        case 'TT': return d.getHours() < 12 ? 'AM' : 'PM';
                        case 'Z': return d.toUTCString().match(/[A-Z]+$/);
                        // Return quoted strings with the surrounding quotes removed
                        default: return $0.substr(1, $0.length - 2);
                    }
                });
            };

        </script>
        <script>
            var _hmt = _hmt || []; (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
            })();
        </script>
    </body>

</html>
